var fs = require("fs");
var _ = require("lodash");

let fileNameB = "../extra";
let fileNameC = "./data/summon";
let outputFileName = "./lua/summon.lua";

let extraData = JSON.parse(fs.readFileSync(`${fileNameB}.json`).toString()).summon;
let mainData = JSON.parse(fs.readFileSync(`${fileNameC}.json`).toString());

let extraMap = new Map();
_.forEach(extraData, (e) => {
    let id = e.id;
    let data = {
        add_date: e.add_date,
    };
    extraMap.set(id, data);
});

let output = `local p = {}
`

_.forEach(mainData, (e) => {
    let data = e.data;
    let exData = extraMap.has(e.id) ? extraMap.get(e.id) : {};

    let str = `p['${e.id}'] = {
    ['name'] = '${data.name}',
    ['element'] = '${data.summonElement}',
    ['series'] = '${data.summonSeries}',
    ['description'] = '${data.description}',
    ['type'] = '${data.type}',
    ['height'] = '${data.height}',
    ['code'] = '${data.code}',
    ['weight'] = '${data.weight}',
    ['enName'] = '${data.enName}',
    ['prefix'] = '${data.prefix}',
    ['data'] = '${data.data}',
    ['energy'] = '${data.summonStage[data.summonStage.length - 1].baseEnergy}',
    ['addDate'] = ${exData.add_date || "''"},
}
`;
    output += str;
});
output += `return p`

fs.writeFileSync(outputFileName, output);